package org.ncibi.cytoscape.metscape.multidisplay.gui.select;

/* 
 * Copy modified from http://www.jguru.com/faq/view.jsp?EID=87579
 * User: mkovalenko
 * Date: Oct 16, 2001
 * Time: 6:09:23 PM
 * Describe file
 */

import java.awt.Container;
import java.util.Vector;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;

public class TableUtil {
	protected TableUtil() {
	}

	public static boolean isRowHeaderVisible(JTable table) {
		Container p = table.getParent();
		if (p instanceof JViewport) {
			Container gp = p.getParent();
			if (gp instanceof JScrollPane) {
				JScrollPane scrollPane = (JScrollPane) gp;
				JViewport rowHeaderViewPort = scrollPane.getRowHeader();
				if (rowHeaderViewPort != null)
					return rowHeaderViewPort.getView() != null;
			}
		}
		return false;
	}

	/**
	 * * Creates row header for table with row number (starting with 1)
	 * displayed
	 */
	public static void removeRowHeader(JTable table) {
		Container p = table.getParent();
		if (p instanceof JViewport) {
			Container gp = p.getParent();
			if (gp instanceof JScrollPane) {
				JScrollPane scrollPane = (JScrollPane) gp;
				scrollPane.setRowHeader(null);
			}
		}
	}

	/**
	 * * Creates row header for table with row number (starting with 1)
	 * displayed
	 * @param rowHeaderVector 
	 */
	public static TableRowHeader setRowHeader(JTable table, Vector<String> rowHeaderVector) {
		TableRowHeader header = null;
		Container p = table.getParent();
		if (p instanceof JViewport) {
			Container gp = p.getParent();
			if (gp instanceof JScrollPane) {
				JScrollPane scrollPane = (JScrollPane) gp;
				header = new TableRowHeader(table,rowHeaderVector);
				scrollPane.setRowHeaderView(header);
				return header;
			}
		}
		return null;
	}

	public static String animationLabel(int i) {
		return "DataSeries_" + String.valueOf(i);
	}
} 
